package com.liuliang.repository;

import com.liuliang.entity.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * 资源访问层：StudentRepository接口，继承JpaRepository接口
 * 参数一 T：当前需要映射的实体
 * 参数二 ID：当前映射的实体中的OID（映射对象标识符，数据库主键）的类型
 */
@Repository
public interface StudentRepository extends JpaRepository<Student, Integer> {
    //模糊查询（使用原生SQL需要加上：nativeQuery = true）
    @Query(value = "select * from t_student where name like %?1% and birthplace like %?2% and major like %?3%",
            nativeQuery = true)
    Page<Student> findByLike(String name, String birthplace, String major, Pageable pageable);
}